#include <iostream>
#include <stdio.h>
#include <string.h>
#include <cassert>
#include <string>
#include <unistd.h>
#include <cerrno>
#include <fcntl.h>
#include "street.hpp"
using namespace std;
int main()
{
    umask(0);
    int ret = mkfifo(name.c_str(), 0666);
    if (ret != 0)
    {
        cerr << errno << ":" << strerror(errno) << endl;
        return 1;
    }
    cout << "I don't have opened the file" << endl;
    int fd = open(name.c_str(), O_RDONLY);
    if (fd < 0)
    {
        cerr << errno << ":" << strerror(errno) << endl;
        return 2;
    }
    cout << "I ready to communication with my customer" << endl;
    // 开始通信
    char buf[MAX] = {0};
    while (true)
    {
        int n = read(fd, buf, sizeof(buf) - 1);
        buf[n] = '\0';
        if (n > 0)
        {
            cout << "I have received customer message:" << buf << endl;
        }
        else if (n == 0)
        {
            cout << "customer quit,me too" << endl;
            break;
        }
        else
        {
            cout << "read error" << endl;
        }
    }
    unlink(name.c_str());
    close(fd);
    return 0;
}